package com.swak.fx.support.transition;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Supplier;

import javafx.util.Duration;

@SuppressWarnings("rawtypes") 
public class UIKeyFrame {

	private Duration duration;
	private Set<UIKeyValue<?>> keyValues = new CopyOnWriteArraySet<>();
	private Supplier<Boolean> animateCondition = null;

	public UIKeyFrame(Duration duration, UIKeyValue... keyValues) {
		this.duration = duration;
		for (final UIKeyValue keyValue : keyValues) {
			if (keyValue != null) {
				this.keyValues.add(keyValue);
			}
		}
	}

	private UIKeyFrame() {
	}

	public final Duration getDuration() {
		return duration;
	}

	public final Set<UIKeyValue<?>> getValues() {
		return keyValues;
	}

	public Supplier<Boolean> getAnimateCondition() {
		return animateCondition;
	}

	public static Builder builder() {
		return new Builder();
	}

	public static final class Builder {
		private Duration duration;
		private Set<UIKeyValue<?>> keyValues = new CopyOnWriteArraySet<>();
		private Supplier<Boolean> animateCondition = null;

		private Builder() {
		}

		public Builder setDuration(Duration duration) {
			this.duration = duration;
			return this;
		}

		public Builder setKeyValues(UIKeyValue... keyValues) {
			for (final UIKeyValue keyValue : keyValues) {
				if (keyValue != null) {
					this.keyValues.add(keyValue);
				}
			}
			return this;
		}

		public Builder setAnimateCondition(Supplier<Boolean> animateCondition) {
			this.animateCondition = animateCondition;
			return this;
		}

		public UIKeyFrame build() {
			UIKeyFrame UIKeyFrame = new UIKeyFrame();
			UIKeyFrame.duration = this.duration;
			UIKeyFrame.keyValues = this.keyValues;
			UIKeyFrame.animateCondition = this.animateCondition;
			return UIKeyFrame;
		}
	}
}
